package com.hfuu.controller.check;

import com.hfuu.model.ResponseEntity;
import com.hfuu.model.ResponseEntityBuilder;
import com.hfuu.service.check.FileDataService;
import com.hfuu.service.check.request.FileDataRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.core.MediaType;

/**
 * Author: admin
 * Date: 2018/4/26
 * time: 上午10:03
 */
@RestController
@RequestMapping("/api/check")
public class FileDataController {

    @Autowired
    private FileDataService fileDataService;

    /**
     * 组织注册审核资料上传
     *
     * @param request
     * @param
     * @return
     */
    @RequestMapping(value = "/registerOrginzerCheck" , method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity<String> RegisterOrginzerCheck(@RequestParam("file") MultipartFile file,
                                                        @RequestParam("userId") String userId)
            throws Exception {

        FileDataRequest request = new FileDataRequest();
        request.setFile(file);
        request.setUserId(Integer.valueOf(userId));
        return ResponseEntityBuilder.success(fileDataService.registerOrginzerCheck(request));
    }

    /**
     * 组织注册审核资料删除
     *
     * @param file
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteOrginzeData" , method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Object> deleteOrginzeData(@RequestBody FileDataRequest request)
            throws Exception {
        return ResponseEntityBuilder.success(fileDataService.deleteOrginzeData(request.getFileName()));
    }

    /**
     * 用户通过ID获得所有审核材料
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/getAllOrginzeData" , method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Object> getAllOrginzeData(@RequestBody FileDataRequest request)
            throws Exception {
        return ResponseEntityBuilder.success(fileDataService.getAllOrginzeData(request));
    }

    /**
     * 下载审核资料
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/getDataSource" , method = RequestMethod.GET)
    @ResponseBody
    public org.springframework.http.ResponseEntity<byte[]> getDataSource(@RequestParam("id") Integer id)
            throws Exception {
        return fileDataService.getDataSource(id);
    }

    /**
     * 下载审核资料
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/getPicFile" , method = RequestMethod.GET)
    @ResponseBody
    public org.springframework.http.ResponseEntity<byte[]> getPicFile(@RequestParam("filePath") String filePath,
                                                                      @RequestParam("fileName") String fileName)
            throws Exception {
        return fileDataService.getPicFile(filePath, fileName);
    }
}
